package com.pocket.mic.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Game {

	private Long id;
	private Date startTime;
	private Date endTime;	
	
	//the button's location
	private int buttonNo;
	//the first player
	private int startNo;
	//the last bet player
	private int maxBetNo;
	
	private int bet;//需要跟注所需的注码大小，这里的值是指总的值，bet - 你现在已经投入桌上的钱 = 你需要继续投入桌上的钱。
	//current op player
	private int curOperator;
	
	private int currentround;//当前回合 0-无公共牌:Perflop 1-3张公共牌:Flop 2-4张公共牌:Turn 3-5张公共牌:River
	
	private int isAnybetAdded;//是否有人加注，若有人加注则一轮循环延长到addbetposition
	
	private int alivePlayerCount;
	
	private int mainPool;
	//TODO: set side pool
	private int[] sidePools_1;
	private int[] sidePools_2;
	private int[] sidePools_3;
	private int[] sidePools_4;
	
	private Desk desk;
	
	private List<Card> cards=new ArrayList<Card>(5);
	
	private List<Player> players=new ArrayList<Player>();
	
	//waiting list
	private List<Player> waitingPlayers=new ArrayList<Player>();
	
	private String winner;
	
	public String getWinner() {
		return winner;
	}

	public void setWinner(String winner) {
		this.winner = winner;
	}

	public int getButtonNo() {
		return buttonNo;
	}

	public void setButtonNo(int buttonNo) {
		this.buttonNo = buttonNo;
	}

	public int getStartNo() {
		return startNo;
	}

	public void setStartNo(int startNo) {
		this.startNo = startNo;
	}

	public int getMaxBetNo() {
		return maxBetNo;
	}

	public void setMaxBetNo(int maxBetNo) {
		this.maxBetNo = maxBetNo;
	}

	public int getBet() {
		return bet;
	}

	public void setBet(int bet) {
		this.bet = bet;
	}

	public int getCurOperator() {
		return curOperator;
	}

	public void setCurOperator(int curOperator) {
		this.curOperator = curOperator;
	}

	public int getCurrentround() {
		return currentround;
	}

	public void setCurrentround(int currentround) {
		this.currentround = currentround;
	}

	public int getIsAnybetAdded() {
		return isAnybetAdded;
	}

	public void setIsAnybetAdded(int isAnybetAdded) {
		this.isAnybetAdded = isAnybetAdded;
	}

	public int getAlivePlayerCount() {
		return alivePlayerCount;
	}

	public void setAlivePlayerCount(int alivePlayerCount) {
		this.alivePlayerCount = alivePlayerCount;
	}

	public int getMainPool() {
		return mainPool;
	}

	public void setMainPool(int mainPool) {
		this.mainPool = mainPool;
	}


	public int[] getSidePools_1() {
		return sidePools_1;
	}

	public void setSidePools_1(int[] sidePools_1) {
		this.sidePools_1 = sidePools_1;
	}

	public int[] getSidePools_2() {
		return sidePools_2;
	}

	public void setSidePools_2(int[] sidePools_2) {
		this.sidePools_2 = sidePools_2;
	}

	public int[] getSidePools_3() {
		return sidePools_3;
	}

	public void setSidePools_3(int[] sidePools_3) {
		this.sidePools_3 = sidePools_3;
	}

	public int[] getSidePools_4() {
		return sidePools_4;
	}

	public void setSidePools_4(int[] sidePools_4) {
		this.sidePools_4 = sidePools_4;
	}

	public List<Player> getWaitingPlayers() {
		return waitingPlayers;
	}

	public void setWaitingPlayers(List<Player> waitingPlayers) {
		this.waitingPlayers = waitingPlayers;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}


	public List<Card> getCards() {
		return cards;
	}

	public void setCards(List<Card> cards) {
		this.cards = cards;
	}

	public Desk getDesk() {
		return desk;
	}

	public void setDesk(Desk desk) {
		this.desk = desk;
	}

	public List<Player> getPlayers() {
		return players;
	}

	public void setPlayers(List<Player> players) {
		this.players = players;
	}
	
	private  Map<Integer,Byte>  baseCards = new  HashMap<Integer,Byte>();
	public void initCards(){
		System.out.println("-----------------------init card-------------------------");
		int  tmp=0;
	    for  (int  i = 0; i <4; i++) {
	        for  (int  m = 0; m < 13; m++) {
	            tmp=((byte )(i)<<4)|((byte )m); //使用位操作构造一张牌
	            baseCards.put(new  Integer (i * 13 + m),new  Byte ((byte )tmp));
	        }
	    }
//	    baseCards.put(new  Integer (53), new  Byte ((byte )0x4d)); //大王
//	    baseCards.put(new  Integer (54), new  Byte ((byte )0x4e)); //小王
	    System.out.println("-----------------------init card end----------------------");
	}
    
	public Card giveCard(){
		if(0>=baseCards.size()){
			initCards();
		}
		int round=baseCards.size()+1;
		int cardId=round;
		while(null==baseCards.get(cardId)){
			cardId=new Long(Math .round(Math .random() * 87) % round).intValue();
		}
		Card card=new Card(cardId,baseCards.get(cardId));
		baseCards.remove(cardId);
		System.out.println("get card:"+cardId+"--size:"+baseCards.size());
		return card;
	}
	
	public static void main(String[] args) {
//		Game.initCards();
		Game game=new Game();
		game.initCards();
		for(int i=1;i<55;i++){
			Card card=game.giveCard();
			System.out.println(i+"ID:"+card.getNo()+"-"+(card.getId().byteValue()>>4)+"-"+(card.getId().byteValue()&0x0f));
		}
//		Iterator<Integer> it=game.baseCards.keySet().iterator();
//		while(it.hasNext()){
//			Integer in=it.next();
//			byte b=game.baseCards.get(in);
//			System.out.println(in+"-"+b);
//		}
	}
}
